// 通用方法

/**
 * 文件转链接
 * @param file
 * @returns 预览链接
 */
export function getObjectURL(file: File | Blob) {
  let url = '';

  if ((window as any).createObjectURL !== undefined) {
    url = (window as any).createObjectURL(file);
  } else if (window.URL !== undefined) {
    url = window.URL.createObjectURL(file);
  } else if (window.webkitURL !== undefined) {
    url = window.webkitURL.createObjectURL(file);
  }
  return url;
}

/**
 * 销毁createObjectURL
 * @param objectURL
 */

export function removeObjectURL(objectURL: string) {
  if (/^blob:/.test(objectURL)) {
    if ((window as any).revokeObjectURL !== undefined) {
      (window as any).revokeObjectURL(objectURL);
    } else if (window.URL !== undefined) {
      window.URL.revokeObjectURL(objectURL);
    } else if (window.webkitURL !== undefined) {
      window.webkitURL.revokeObjectURL(objectURL);
    }
  }
}
